#ifndef UDPRECEIVE_H
#define UDPRECEIVE_H

#include <QObject>
#include <QUdpSocket>
#include <QImage>
#include <QByteArray>
#include <QBuffer>
#include <QDateTime>
#include <QTimer>
#include <QDebug>
#include <opencv2/opencv.hpp>
#include <QLabel>
class UDPReceive : public QObject
{
Q_OBJECT
public:
    explicit  UDPReceive(QObject *parent = nullptr);
    ~UDPReceive();

signals:
    void sendDisplaySignal(const cv::Mat &image); //send signal to show image

public slots:
    void startReceiving(const QString &address, const quint16 &port);
    void processPendingDatagrams();
    void socketStateChanged(QAbstractSocket::SocketState state);
    void checkConnectionStatus();
    void  createDirectory(); //创建目录
private:
    cv::Mat decodeImage(std::vector<uchar> &data);
    void saveImage(const cv::Mat &image);
    void sendRequest();  //发送请求数据

    QString getCurrentTime(); //获取当前时间

    QUdpSocket* udpSocket;
    QHostAddress m_address;
    quint16  m_port;
    QTimer* m_connectionTimer; //开启连接状态显示
    bool m_conneted;
    bool m_closeState; //主动关闭状态
    QString m_Path;//返回文件路径
};

#endif // UDPRECEIVE_H
